package com.edt.ichannel.api.service.impl;

import cc.edt.iceutils2.random.IceRandomUtils;
import com.edt.ichannel.api.common.entity.ActionResult;
import com.edt.ichannel.api.dao.DownlinkSendDao;
import com.edt.ichannel.api.entiy.local.DownlinkSend;
import com.edt.ichannel.api.service.DownlinkSendService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;


/**
 * 下行发送相关
 *
 * @author 宋寒
 * @date 2018/7/5 11:51
 */
@Service
public class DownlinkSendServiceImpl implements DownlinkSendService {

    @Resource
    private DownlinkSendDao downlinkSendDao;


    @Transactional(rollbackFor = Exception.class)
    @Override
    public ActionResult saveDownlinkSend(DownlinkSend downlinkSend) {
        ActionResult actionResult = new ActionResult();
        downlinkSend.setId(IceRandomUtils.longUUID());
        //短信流水
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
        String messageFlow = formatter.format(new Date());
        downlinkSend.setMessageFlow(messageFlow);
        downlinkSend.setSendDate(new Date());
        downlinkSend.setSubmissionDate(new Date());
        downlinkSend.setPriority("1");
        downlinkSendDao.saveDownlinkSend(downlinkSend);
        actionResult.setSuccess(true);
        actionResult.setMessage("保存成功");
        return actionResult;
    }
}
